package Recomendadores.Semantico;

import java.util.ArrayList;
import java.util.Iterator;

import com.hp.hpl.jena.ontology.Individual;

public class PropertySequence {
	
	private ArrayList<Individual> sequence;
	
	public PropertySequence(){
		sequence = new ArrayList<Individual>();
	}
	
	public PropertySequence(ArrayList<Individual> array){
		sequence = new ArrayList<Individual>();
		Iterator<Individual> i = array.iterator();
		while (i.hasNext()) {
			sequence.add(i.next());
		}
	}
	
	public void add(Individual res){
		if(res!=null) 
			sequence.add(res);
	}

	public ArrayList<Individual> getSequence() {
		return sequence;
	}

	public int length() {
		return sequence.size();
	}

	public Individual getNode(int j) {
		return sequence.get(j);
	}

	//retorna el indice de un individual en la secuencia
	public int getIndex(Individual ind) {
		Iterator<Individual> i = sequence.iterator();
		int count = 0;
		while(i.hasNext()){
			Individual aux = i.next();
			if(aux.equals(ind)){
				return count;
			}
			count++;
		}
		return -1;
	}

	//retorna una sub secuencia que termina en el individual index
	public PropertySequence getSubSequence(int index) {
		PropertySequence sub = new PropertySequence();
		for(int i=0; i<=index;i++){
			sub.add(sequence.get(i));
		}
		return sub;
	}
	
	/*una secuencia de propiedades es igual a otra 
	 *si todas sus Instancias son iguales una a una*/
	public boolean equals(PropertySequence sequence) {		
		
		//si tienen el mismo largo las recorro
		if(sequence.length()==this.length()){	
			boolean sonIguales = true;

			Iterator<Individual> i = sequence.getSequence().iterator();
			Iterator<Individual> j = this.getSequence().iterator();
			while(i.hasNext() && j.hasNext()){
				Individual esta = j.next();
				Individual laOtra = i.next();
				if(!esta.getURI().equals(laOtra.getURI())){
					sonIguales = false;
				}			
			}
			return sonIguales;
		}else{
			return false;
		}
	}
	
	

}
